
{
var propagete;
var update;
var BgL_forzd2eachzd2yxz00;
var BgL_validzd2coordzf3z21;
var BgL_startzd2gamezd2;
var BgL_effectzd2proczd2;
var BgL_cellzd2refzd2;
var timer;
var BgL_datazd2colorszd2;
var BgL_animzd2gridzd2;
var BgL_htmlzd2cellzd2;
var grid;
var height;
var BgL_cellzd2setz12zc0;
var width;
var BgL_setzd2htmlzd2cellzd2colorz12zc0;
var BgL_selectzd2effectz12zc0;
var BgL_makezd2gridzd2;
var BgL_randomzd2intzd2;

{
(width = 18);
(height = 18);
(grid = null);
(BgL_animzd2gridzd2 = null);
(BgL_datazd2colorszd2 = ["#2ca9e1", "#4d5aaf", "#867ba9", "#dbd0e6"]);
(timer = (0));
(BgL_effectzd2proczd2 = (0));
(BgL_startzd2gamezd2 = function(sc_mode_1)
{
return ((grid = (BgL_makezd2gridzd2(height, width))), (BgL_animzd2gridzd2 = (BgL_makezd2gridzd2(height, width))), (BgL_forzd2eachzd2yxz00(function(sc_y_2, sc_x_3)
{
var sc_el_4;
var sc_val2018_5;

{
switch (sc_mode_1) {
case (0):
(BgL_cellzd2setz12zc0(grid, sc_y_2, sc_x_3, (BgL_randomzd2intzd2(4))));

break;
case 1:
(BgL_cellzd2setz12zc0(grid, sc_y_2, sc_x_3, (0)));

break;
case 2:
(BgL_cellzd2setz12zc0(grid, sc_y_2, sc_x_3, (sc_y_2%4)));

break;
case 3:
(BgL_cellzd2setz12zc0(grid, sc_y_2, sc_x_3, ((sc_y_2+sc_x_3)%4)));

break;
}
(BgL_setzd2htmlzd2cellzd2colorz12zc0(sc_y_2, sc_x_3, (BgL_cellzd2refzd2(grid, sc_y_2, sc_x_3))));
(sc_el_4 = (BgL_htmlzd2cellzd2(sc_y_2, sc_x_3)));
sc_el_4["setOpacity"](1);
sc_el_4["show"]();
(sc_val2018_5 = Event["observe"]((BgL_htmlzd2cellzd2(sc_y_2, sc_x_3)), "click", function()
{
return (propagete(sc_y_2, sc_x_3, 1));

}
, false));
return sc_val2018_5;
}

}
, height, width)), window["clearInterval"](timer), (timer = window["setInterval"](update, 50)));

}
);
(update = function()
{
return (BgL_forzd2eachzd2yxz00(function(sc_y_6, sc_x_7)
{
var sc_val_8;
return ((sc_val_8 = (BgL_cellzd2refzd2(BgL_animzd2gridzd2, sc_y_6, sc_x_7))), ((sc_val_8>(0))?
(BgL_cellzd2setz12zc0(BgL_animzd2gridzd2, sc_y_6, sc_x_7, (sc_val_8-2))):
((sc_val_8<(0))?
((BgL_setzd2htmlzd2cellzd2colorz12zc0(sc_y_6, sc_x_7, (BgL_cellzd2refzd2(grid, sc_y_6, sc_x_7)))), new BgL_effectzd2proczd2((BgL_htmlzd2cellzd2(sc_y_6, sc_x_7))), (BgL_cellzd2setz12zc0(BgL_animzd2gridzd2, sc_y_6, sc_x_7, (0)))):
undefined)));

}
, height, width));

}
);
(propagete = function(sc_y_9, sc_x_10, sc_delay_11)
{
var sc_cy_15;
var sc_cy_19;
var sc_cy_23;
var sc_cy_27;
var sc_lis_14;
var sc_lis_16;
var sc_lis_18;
var sc_lis_20;
var sc_cx_17;
var sc_val2019_13;
var sc_lis_22;
var sc_lis_24;
var sc_cx_21;
var sc_lis_26;
var sc_cx_25;
var sc_lis_28;
var sc_cx_29;
var sc_val_12;

{
(sc_val_12 = (((BgL_cellzd2refzd2(grid, sc_y_9, sc_x_10))+1)%4));
(BgL_cellzd2setz12zc0(grid, sc_y_9, sc_x_10, sc_val_12));
(BgL_cellzd2setz12zc0(BgL_animzd2gridzd2, sc_y_9, sc_x_10, sc_delay_11));
switch (sc_val_12) {
case (0):

{
(sc_lis_14 = (sci_list(1, 2)));
(sc_cy_15 = (sc_y_9-1));
if (((BgL_validzd2coordzf3z21(sc_cy_15, sc_x_10))!== false)) if (((sci_memq((BgL_cellzd2refzd2(grid, sc_cy_15, sc_x_10)), sc_lis_14)) instanceof sc_Pair)) (propagete(sc_cy_15, sc_x_10, (sc_delay_11+2)));

else
undefined;

else
undefined;
(sc_lis_16 = (sci_list(2, 3)));
(sc_cx_17 = (sc_x_10+1));
if (((BgL_validzd2coordzf3z21(sc_y_9, sc_cx_17))!== false)) if (((sci_memq((BgL_cellzd2refzd2(grid, sc_y_9, sc_cx_17)), sc_lis_16)) instanceof sc_Pair)) (sc_val2019_13 = (propagete(sc_y_9, sc_cx_17, (sc_delay_11+2))));

else
(sc_val2019_13 = undefined);

else
(sc_val2019_13 = undefined);
}

break;
case 1:

{
(sc_lis_18 = (sci_list((0), 3)));
(sc_cy_19 = (sc_y_9+1));
if (((BgL_validzd2coordzf3z21(sc_cy_19, sc_x_10))!== false)) if (((sci_memq((BgL_cellzd2refzd2(grid, sc_cy_19, sc_x_10)), sc_lis_18)) instanceof sc_Pair)) (propagete(sc_cy_19, sc_x_10, (sc_delay_11+2)));

else
undefined;

else
undefined;
(sc_lis_20 = (sci_list(2, 3)));
(sc_cx_21 = (sc_x_10+1));
if (((BgL_validzd2coordzf3z21(sc_y_9, sc_cx_21))!== false)) if (((sci_memq((BgL_cellzd2refzd2(grid, sc_y_9, sc_cx_21)), sc_lis_20)) instanceof sc_Pair)) (sc_val2019_13 = (propagete(sc_y_9, sc_cx_21, (sc_delay_11+2))));

else
(sc_val2019_13 = undefined);

else
(sc_val2019_13 = undefined);
}

break;
case 2:

{
(sc_lis_22 = (sci_list((0), 3)));
(sc_cy_23 = (sc_y_9+1));
if (((BgL_validzd2coordzf3z21(sc_cy_23, sc_x_10))!== false)) if (((sci_memq((BgL_cellzd2refzd2(grid, sc_cy_23, sc_x_10)), sc_lis_22)) instanceof sc_Pair)) (propagete(sc_cy_23, sc_x_10, (sc_delay_11+2)));

else
undefined;

else
undefined;
(sc_lis_24 = (sci_list((0), 1)));
(sc_cx_25 = (sc_x_10-1));
if (((BgL_validzd2coordzf3z21(sc_y_9, sc_cx_25))!== false)) if (((sci_memq((BgL_cellzd2refzd2(grid, sc_y_9, sc_cx_25)), sc_lis_24)) instanceof sc_Pair)) (sc_val2019_13 = (propagete(sc_y_9, sc_cx_25, (sc_delay_11+2))));

else
(sc_val2019_13 = undefined);

else
(sc_val2019_13 = undefined);
}

break;
case 3:

{
(sc_lis_26 = (sci_list(1, 2)));
(sc_cy_27 = (sc_y_9-1));
if (((BgL_validzd2coordzf3z21(sc_cy_27, sc_x_10))!== false)) if (((sci_memq((BgL_cellzd2refzd2(grid, sc_cy_27, sc_x_10)), sc_lis_26)) instanceof sc_Pair)) (propagete(sc_cy_27, sc_x_10, (sc_delay_11+2)));

else
undefined;

else
undefined;
(sc_lis_28 = (sci_list((0), 1)));
(sc_cx_29 = (sc_x_10-1));
if (((BgL_validzd2coordzf3z21(sc_y_9, sc_cx_29))!== false)) if (((sci_memq((BgL_cellzd2refzd2(grid, sc_y_9, sc_cx_29)), sc_lis_28)) instanceof sc_Pair)) (sc_val2019_13 = (propagete(sc_y_9, sc_cx_29, (sc_delay_11+2))));

else
(sc_val2019_13 = undefined);

else
(sc_val2019_13 = undefined);
}

break;
}
return sc_val2019_13;
}

}
);
(BgL_htmlzd2cellzd2 = function(sc_y_30, sc_x_31)
{
return document["getElementById"](("grid-"+sc_y_30+"-"+sc_x_31));

}
);
(BgL_setzd2htmlzd2cellzd2colorz12zc0 = function(sc_y_32, sc_x_33, sc_col_34)
{
var sc_el_35;
return ((sc_el_35 = (BgL_htmlzd2cellzd2(sc_y_32, sc_x_33))), ((sc_el_35["style"])["background"] = (BgL_datazd2colorszd2[sc_col_34])));

}
);
(BgL_selectzd2effectz12zc0 = function(sc_n_36)
{
var sc_val2020_37;

{
switch (sc_n_36) {
case (0):
(BgL_effectzd2proczd2 = (Effect["Highlight"]));

break;
case 1:
(BgL_effectzd2proczd2 = (Effect["Fade"]));

break;
case 2:
(BgL_effectzd2proczd2 = (Effect["Appear"]));

break;
case 3:
(BgL_effectzd2proczd2 = (Effect["Puff"]));

break;
case 4:
(BgL_effectzd2proczd2 = (Effect["BlindUp"]));

break;
case 5:
(BgL_effectzd2proczd2 = (Effect["BlindDown"]));

break;
case 6:
(BgL_effectzd2proczd2 = (Effect["SwitchOff"]));

break;
case 7:
(BgL_effectzd2proczd2 = (Effect["DropOut"]));

break;
case 8:
(BgL_effectzd2proczd2 = (Effect["Shake"]));

break;
case 9:
(BgL_effectzd2proczd2 = (Effect["SlideDown"]));

break;
case 10:
(BgL_effectzd2proczd2 = (Effect["SlideUp"]));

break;
case 11:
(BgL_effectzd2proczd2 = (Effect["Squish"]));

break;
case 12:
(BgL_effectzd2proczd2 = (Effect["Grow"]));

break;
case 13:
(BgL_effectzd2proczd2 = (Effect["Shrink"]));

break;
case 14:
(BgL_effectzd2proczd2 = (Effect["Pulsate"]));

break;
case 15:
(BgL_effectzd2proczd2 = (Effect["Fold"]));

break;
}
(sc_val2020_37 = undefined);
return sc_val2020_37;
}

}
);
(BgL_validzd2coordzf3z21 = function(sc_y_38, sc_x_39)
{
return ((sc_y_38>=(0))?
((sc_y_38<height)?
((sc_x_39>=(0))?
(sc_x_39<width):
false):
false):
false);

}
);
(BgL_makezd2gridzd2 = function(sc_h_40, sc_w_41)
{
return (sci_list2vector((sci_map(function(sc_l_42)
{
return (sci_makeVector(sc_w_41, (0)));

}
, (sci_makeList(sc_h_40))))));

}
);
(BgL_cellzd2setz12zc0 = function(sc_gr_43, sc_y_44, sc_x_45, sc_val_46)
{
return ((sc_gr_43[sc_y_44])[sc_x_45] = sc_val_46);

}
);
(BgL_cellzd2refzd2 = function(sc_gr_47, sc_y_48, sc_x_49)
{
return ((sc_gr_47[sc_y_48])[sc_x_49]);

}
);
(BgL_forzd2eachzd2yxz00 = function(sc_fun_50, sc_h_51, sc_w_52)
{
var sc_y_53;
var sc_x_55;
var sc_val2021_54;

{
(sc_y_53 = (0));
BgL_reczd2call2007zd2: while (true) {if ((sc_y_53<sc_h_51)) 
{
(sc_x_55 = (0));
BgL_reczd2call2006zd2: while (true) {if ((sc_x_55<sc_w_52)) 
{
(sc_fun_50(sc_y_53, sc_x_55));
(++sc_x_55);
continue BgL_reczd2call2006zd2;
}

else
undefined;
break BgL_reczd2call2006zd2;
}
(++sc_y_53);
continue BgL_reczd2call2007zd2;
}

else
(sc_val2021_54 = undefined);
break BgL_reczd2call2007zd2;
}
return sc_val2021_54;
}

}
);
(BgL_randomzd2intzd2 = function(sc_n_56)
{
return Math["floor"]((Math["random"]()*sc_n_56));

}
);
}

}

